package com.tony.demo.test;

import java.io.File;

public class RenameAndMoveFile {
    //    private static String path = "F:\\视频\\综艺\\宇宙时空之旅\\宇宙时空";
//    private static String videoPath = "F:\\视频\\综艺\\宇宙时空之旅\\宇宙时空\\视频\\";
    private static String chmPath = "F:\\视频\\综艺\\宇宙时空之旅\\宇宙时空\\chm文件\\";
//    private static String torrentPath = "F:\\视频\\综艺\\宇宙时空之旅\\宇宙时空\\torrent\\";

    private static String path = "E:\\迅雷下载";
    private static String videoPath = "E:\\AV\\视频\\";
    private static String torrentPath = "E:\\AV\\torrent\\";

    public static void main(String[] args) {
        File file1 = new File(videoPath);
        if (!file1.exists()) {
            file1.mkdirs();
        }
        File file2 = new File(torrentPath);
        if (!file2.exists()) {
            file2.mkdirs();
        }

        moveFile(path);
    }

    private static void moveFile(String path) {
        File file = new File(path);
        if (file.exists()) {
            if (file.isDirectory()) {
                File[] files = file.listFiles();
                for (File tempFile : files) {
                    String tempPath = tempFile.getAbsolutePath();
                    if (!tempPath.equals(videoPath) && !tempPath.equals(chmPath) && !tempPath.equals(torrentPath)) {
                        moveFile(tempPath);
                    }
                }
            } else {
                String name = file.getName();
                if (name.endsWith(".mp4") || name.endsWith(".mkv") ||
                        name.endsWith("avi") || name.endsWith(".rmvb") || name.endsWith(".png")) {
                    //视频
                    String targetPath = new StringBuilder(videoPath).append(name).toString();
                    if (targetPath.contains("有码中字")) {
                        return;
                    }
                    file.renameTo(new File(targetPath));
                } else if (name.endsWith(".chm")) {
                    //chm文件
                    String targetPath = new StringBuilder(chmPath).append(name).toString();
                    file.renameTo(new File(targetPath));
                } else if (name.endsWith(".torrent")) {
                    //torrent文件
                    String targetPath = new StringBuilder(torrentPath).append(name).toString();
                    file.renameTo(new File(targetPath));
                } else {
//                    file.delete();
                }
                System.out.println("DMLog*******  " + name);
            }
        }
    }
}
